/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cl.mechon.buchef.engine;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.Log;

/**
 *
 * @author Linkup
 */
public class GameLogic {

    Map<String, Entity> game_Entities;

    public GameLogic() {

        game_Entities = new HashMap<String, Entity>();
    }

    public void update(GameContainer container, StateBasedGame sb, int delta) throws SlickException {
        //Log.info("GameLogic updating");
        Vector2f playerPosition = game_Entities.get("player").getPosition();
        if (container.getInput().isKeyDown(Input.KEY_LEFT)) {
            game_Entities.get("player").setPosition(playerPosition.add(new Vector2f(-1, 0)));
        }
        if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {
            game_Entities.get("player").setPosition(playerPosition.add(new Vector2f(1, 0)));
        }
        if (container.getInput().isKeyDown(Input.KEY_UP)) {
            game_Entities.get("player").setPosition(playerPosition.add(new Vector2f(0, -1)));
        }
        if (container.getInput().isKeyDown(Input.KEY_DOWN)) {
            game_Entities.get("player").setPosition(playerPosition.add(new Vector2f(0, 1)));
        }
        Log.info(" GameLogic updating: player position = (" + playerPosition.getX() + "," + playerPosition.getY() + ")");
    }

    public int loadMap() throws SlickException {
        
        MBMap my_map=new MBMap("map", "assets/maps/test.tmx");
        
        my_map.setLayer(0);
        game_Entities.put("map",my_map );

        return 0;
    }
    
    public int loadPlayer() throws SlickException{
        
        MBPlayer my_player = new MBPlayer("player");
        
        my_player.setLayer(1);
        
        game_Entities.put("player",my_player);
        
        return 0;
    }
            

    public Collection<Entity> getRenderable() {

        return game_Entities.values();
    }
}
